package cloud.maque.admin.controller;

import cloud.maque.admin.annotations.TenantId;
import cloud.maque.admin.annotations.TenantQuery;
import cloud.maque.admin.domain.entity.MqPrivilege;
import cloud.maque.admin.service.MqPrivilegeService;
import cloud.maque.framework.common.request.PaginateDataResquest;
import cloud.maque.framework.common.response.ResponseBodyVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自定义权限接口
 *
 * @author zhuyf
 * @date 2023/3/17 20:57
 */
@RestController
@RequestMapping(value = "/privilege")
@Api(tags = "运维-自定义权限接口")
public class PrivilegeController {

    @Autowired
    MqPrivilegeService privilegeService;


    @PostMapping("/list")
    @ApiOperation(value = "自定义权限查询")
    @TenantQuery
    public ResponseBodyVo<PageInfo<MqPrivilege>> page(@RequestBody @ApiParam("查询内容") PaginateDataResquest<MqPrivilege> pageReq) {
        return ResponseBodyVo.Success(privilegeService.page(pageReq));
    }

    @GetMapping("/detail")
    @ApiOperation(value = "自定义权限详情")
    public ResponseBodyVo<MqPrivilege> Detail(@RequestParam("id") String id) {
        return ResponseBodyVo.Success(privilegeService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增权限")
    public ResponseBodyVo<MqPrivilege> insert(@RequestBody @ApiParam("组内容") MqPrivilege group) {
        return ResponseBodyVo.Success(privilegeService.savePrivilege(group));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除权限")
    @TenantQuery
    public ResponseBodyVo<Boolean> Delete(@PathVariable("id") String pid, @TenantId String tenantId) {
        return ResponseBodyVo.Success(privilegeService.delete(pid,tenantId));
    }


}
